/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.ad.feedsreader.actions;

import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSession;
import org.apache.struts2.interceptor.SessionAware;
import ua.ad.feedsreader.mybatis.config.MyBatisSqlSessionFactory;
import ua.ad.feedsreader.mybatis.mappers.beans.ItemFeed;
import ua.ad.feedsreader.mybatis.mappers.beans.Utilizador;
import ua.ad.feedsreader.mybatis.mappers.clients.ItemFeedMapper;

/**
 *
 * @author sexta13
 */
public class MostrarItemsCategoriaAction extends ActionSupport implements SessionAware {

    /**
	 * 
	 */
	private static final long serialVersionUID = -2676735499346845779L;
	private Map<String, Object> session;
    private List<ItemFeed> listaItemFeeds;
    private int idCategoria;

    @Override
    public String execute() throws Exception {
        Utilizador userSession = (Utilizador) getSession().get("utilizador");

        SqlSession bdSession = MyBatisSqlSessionFactory.getSqlSessionFactory().openSession();
        
        ItemFeedMapper itMapper = bdSession.getMapper(ItemFeedMapper.class);
        
        setListaItemFeeds(itMapper.selectItemsByUserAndCategory(userSession.getId(), getIdCategoria()));

        bdSession.close();
        return SUCCESS;
    }

    public Map<String, Object> getSession() {
        return session;
    }

    @Override
    public void setSession(Map<String, Object> session) {
        this.session = session;
    }

    public List<ItemFeed> getListaItemFeeds() {
        return listaItemFeeds;
    }

    public void setListaItemFeeds(List<ItemFeed> listaItemFeeds) {
        this.listaItemFeeds = listaItemFeeds;
    }

    public int getIdCategoria() {
        return idCategoria;
    }

    public void setIdCategoria(int idCategoria) {
        this.idCategoria = idCategoria;
    }
    
    
}
